package com.billing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.billing.model.dao.ConsultationDao;
import com.billing.model.entity.Comment;
import com.billing.model.entity.CommentAppBean;
import com.billing.model.entity.Consultation;
import com.billing.model.entity.ConsultationAppBean;
import com.billing.model.entity.MessageAppBean;
import com.billing.service.ConsultationService;

/**
 * @author Administrator
 *
 */
@Service
public class ConsultationServiceImpl implements ConsultationService {

	@Resource
	private ConsultationDao consultationdao;

	@Override
	public List<Consultation> getConsultationlist(String consultingtitle,
			String art, int organizationid, int currentPage, int pageSize) {
		
		return consultationdao.getConsultationlist(consultingtitle, art,
				organizationid, currentPage, pageSize);
	}

	@Override
	public int selectConsuNum(String consultingtitle, String art,
			int organizationid) {
		return consultationdao.selectConsuNum(consultingtitle, art, organizationid);
	}

	@Override
	public Consultation selectConsubyId(String id) {
		return consultationdao.selectConsubyId(id);
	}

	@Override
	public int insertCons(Consultation consultation) {
		return consultationdao.insertCons(consultation);
	}

	@Override
	public int updateCons(Consultation consultation) {
		return consultationdao.updateCons(consultation);
	}

	@Override
	public int deleteConsByid(int id) {
		return consultationdao.deleteConsByid(id);
	}

	@Override
	public int insertpath(Consultation consultation) {
		return consultationdao.insertpath(consultation);
	}

	@Override
	public Map<String, Object> selConsultationId(int pageSize,int currentPage) {
		int totalNum = consultationdao.InterfaceNum();
		int totalPage = totalNum / pageSize;
		if (totalNum % pageSize != 0) {
			totalPage++;	
		}
		totalPage = totalPage <= 0 ? 1 : totalPage;
		currentPage = currentPage > totalPage ? totalPage : currentPage;
		
		List<ConsultationAppBean> list = consultationdao.selConsultationId((currentPage - 1) * pageSize, pageSize);
		Map<String, Object> map = new HashMap<>();
		map.put("totalNum", totalNum);
		map.put("totalPage", totalPage);
		map.put("total", totalPage);
		map.put("list", list);
		return map;
	}

	@Override
	public Consultation selConsId(String id) {
		return consultationdao.selConsId(id);
	}

	@Override
	public int updatereadtype(Consultation consultation) {
		return consultationdao.updatereadtype(consultation);
	}

	@Override
	public Map<String, Object> selcommentId(String consid, int pageSize,int currentPage) {
		int totalNum = consultationdao.CommentNum(consid);
		int totalPage = totalNum / pageSize;
		if (totalNum % pageSize != 0) {
			totalPage++;	
		}
		totalPage = totalPage <= 0 ? 1 : totalPage;
		currentPage = currentPage > totalPage ? totalPage : currentPage;
		
		List<CommentAppBean> list = consultationdao.selcommentId(consid, (currentPage - 1) * pageSize, pageSize);
		Map<String, Object> map = new HashMap<>();
		map.put("totalNum", totalNum);
		map.put("totalPage", totalPage);
		map.put("total", totalPage);
		map.put("list", list);
		return map;
	}

	@Override
	public int insertComment(Comment comment) {
		return consultationdao.insertComment(comment);
	}

	@Override
	public Comment CommentById(int id, int consid) {
		return consultationdao.CommentById(id, consid);
	}

}
